<%@ page language="java" import="java.util.*,com.fescoservice.model.*" pageEncoding="UTF-8"%>
<%@page import="com.fescoservice.config.PropertiesConfig"%>
<%
	String langfilename = "/resources/message";
	Integer counts =request.getAttribute("counts")==null?0:(Integer) request.getAttribute("counts");
	List linklist =request.getAttribute("linklist")==null?new ArrayList():(List<Link>) request.getAttribute("linklist");
	String linkDept =(String) request.getAttribute("linkDept");
	String linkType =(String) request.getAttribute("linkType");
	int listSize=PropertiesConfig.getInstance().getInt("ListSize.Link");
	int pageNumber =(Integer) request.getAttribute("pageNumber");
	int pageCount =(counts/listSize)+((0==counts%listSize)?0:1);
%>
<%@include file="../common/LocaleManager.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>Fesco Service</title>
		<link rel="stylesheet" href="<%=path%>/js/jquery/themes/redmond/jquery.ui.all.css">
		<script src="<%=path%>/js/jquery/jquery-1.5.1.js"></script>
		<script src="<%=path%>/js/jquery/external/jquery.bgiframe-2.1.2.js"></script>
		<script src="<%=path%>/js/jquery/ui/jquery.ui.core.js"></script>
		<script src="<%=path%>/js/jquery/ui/jquery.ui.widget.js"></script>
		<script src="<%=path%>/js/jquery/ui/jquery.ui.mouse.js"></script>
		<script src="<%=path%>/js/jquery/ui/jquery.ui.button.js"></script>
		<script src="<%=path%>/js/jquery/ui/jquery.ui.draggable.js"></script>
		<script src="<%=path%>/js/jquery/ui/jquery.ui.position.js"></script>
		<script src="<%=path%>/js/jquery/ui/jquery.ui.resizable.js"></script>
		<script src="<%=path%>/js/jquery/ui/jquery.ui.dialog.js"></script>
		<script src="<%=path%>/js/jquery/ui/jquery.effects.core.js"></script>
		<script src="<%=path%>/js/jquery/jquery.pager.js"></script>
		<link rel="stylesheet" href="<%=path%>/css/admin.css">
	
		<style type="text/css">
			
		</style>
		<script type="text/javascript">
			$(function() {
				var tips = $(".validateTips");		
				
				function updateTips(t) {
					tips.text(t).addClass("ui-state-highlight");
					setTimeout(function() {
						tips.removeClass("ui-state-highlight", 1500);
					}, 500);
				}
		
				function checkLength(o, n, min, max) {
					if (o.val().length > max || o.val().length < min) {
						o.addClass("ui-state-error");
						updateTips('<%=resource.getString("FS_T_LENGTH")%> ' + n + ' <%=resource.getString("FS_T_BETWEEN")%> ' + min
								+ ' <%=resource.getString("FS_T_AND")%> ' + max + '<%=resource.getString("FS_T_DOT")%>');
						return false;
					} else {
						return true;
					}
				}
				
				function pageClick(pageclickednumber) { 
					document.forms.mainForm.action = '<%=path%>/action/Link.htm?cmd=list';
					document.forms.mainForm.page.value=pageclickednumber;
					document.forms.mainForm.submit();		
					//$("#pager").pager({ pagenumber: pageclickednumber, pagecount: 15, buttonClickCallback: PageClick 
				}
				$("#btnAdd").button().click(function() {
					$("#dialogAdd").dialog("open");		
				});
				$("#btnSearch").button().click(function() {
					document.forms.mainForm.action = '<%=path%>/action/Link.htm?cmd=list';
					document.forms.mainForm.submit();		
				});

				$("#pager").pager({ pagenumber: <%=pageNumber%>, pagecount: <%=pageCount%>, buttonClickCallback: pageClick }); 
				
				$("#dialogAdd")
						.dialog(
								{
									autoOpen : false,
									height : 240,
									width : 420,
									modal : true,
									buttons : {
										'<%=resource.getString("FS_T_SAVE")%>'  : function() {
											var bValid = true;
											var linkTitle = $("#linkTitle"),
											 	linkUrl = $("#linkUrl"),
											 	allFields = $([]).add(linkTitle).add(linkUrl);
											
											allFields.removeClass("ui-state-error");
		
											bValid = bValid
													&& checkLength(linkTitle,
															'<%=resource.getString("FS_T_LINKTITLE")%>', 1, 80);											
											bValid = bValid
													&& checkLength(linkUrl,
															'<%=resource.getString("FS_T_LINKURL")%>', 8, 160);							
											if(bValid){
											
												document.forms.dialogAddform.action = '<%=path%>/action/Link.htm';
												document.forms.dialogAddform.submit();
											}
										},
										'<%=resource.getString("FS_T_CANCEL")%>'  : function() {
											$(this).dialog("close");
										}
									},
									close : function() {
										$(this).dialog("close");
									}
								});
				
				$("#dialogModify")
						.dialog(
								{
									autoOpen : false,
									height : 240,
									width : 420,
									modal : true,
									buttons : {
										'<%=resource.getString("FS_T_DELETE")%>'  : function() {
																	
											if(confirm('<%=resource.getString("FS_T_CONFIRMDELETE")%><%=resource.getString("FS_T_LINKURL")%><%=resource.getString("FS_T_ASKSUFFIX")%>')){
												document.forms.dialogModifyForm.cmd.value="deleteLink";
												document.forms.dialogModifyForm.action = '<%=path%>/action/Link.htm?cmd=deleteLink';
												document.forms.dialogModifyForm.submit();
											}
										},
										'<%=resource.getString("FS_T_SAVE")%>'  : function() {
											var bValid = true;
											var linkTitle = $("#linkTitleM"),
											 	linkUrl = $("#linkUrlM"),
											 	allFields = $([]).add(linkTitle).add(linkUrl);
											
											allFields.removeClass("ui-state-error");
		
											bValid = bValid
													&& checkLength(linkTitle,
															'<%=resource.getString("FS_T_LINKTITLE")%>', 1, 80);											
											bValid = bValid
													&& checkLength(linkUrl,
															'<%=resource.getString("FS_T_LINKURL")%>', 8, 160);							
											if(bValid){
												document.forms.dialogModifyForm.cmd.value="modifyLink";
												document.forms.dialogModifyForm.action = '<%=path%>/action/Link.htm?cmd=modifyLink';
												document.forms.dialogModifyForm.submit();
											}
										},
										'<%=resource.getString("FS_T_CANCEL")%>'  : function() {
											$(this).dialog("close");
										}
									},
									close : function() {
										$(this).dialog("close");
									}
								});
			});
			
			function modify(id,title,url){
				document.forms.dialogModifyForm.linkId.value=id;
				document.forms.dialogModifyForm.linkTitle.value=title;
				document.forms.dialogModifyForm.linkUrl.value=url;
				$("#dialogModify").dialog("open");		
			}
		</script>
	</head>
	<body>
		
		<div class="wrapContent">		
			<div id="dialogAdd" title="<%=resource.getString("FS_T_ADD")%> <%=resource.getString("FS_T_LINK")%>">
				<p class="validateTips">
			
				</p>
				<form name="dialogAddform">
					<fieldset>
						<input type="hidden" name="cmd" value="addLink" />
						<input type="hidden" name="linkType" value="<%=linkType %>" />
						<input type="hidden" name="linkDept" value="<%=linkDept %>" />
						<label for="linkTitle">
							<%=resource.getString("FS_T_LINKTITLE")%>
						</label>
						<input type="text" name="linkTitle" maxlength="80" id="linkTitle"
							class="text ui-widget-content ui-corner-all" />
						<label for="linkUrl">
							<%=resource.getString("FS_T_LINKURL")%>
						</label>
						<input type="text" name="linkUrl" id="linkUrl" value="http://"
							class="text ui-widget-content ui-corner-all" />
					</fieldset>					
				</form>
			</div>
			<div id="dialogModify" title="<%=resource.getString("FS_T_MODIFY")%> <%=resource.getString("FS_T_LINK")%>">
				<p class="validateTips">
			
				</p>
				<form name="dialogModifyForm">
					<fieldset>
						<input type="hidden" name="linkId" />
						<input type="hidden" name="cmd" value="modifyLink" />
						<input type="hidden" name="linkType" value="<%=linkType %>" />
						<input type="hidden" name="linkDept" value="<%=linkDept %>" />
						<label for="linkTitle">
							<%=resource.getString("FS_T_LINKTITLE")%>
						</label>
						<input type="text" name="linkTitle" maxlength="80" id="linkTitleM"
							class="text ui-widget-content ui-corner-all" />
						<label for="linkUrl">
							<%=resource.getString("FS_T_LINKURL")%>
						</label>
						<input type="text" name="linkUrl" id="linkUrlM" value="http://"
							class="text ui-widget-content ui-corner-all" />
					</fieldset>					
				</form>
			</div>
		
			<form name="mainForm" method="post">
				<input type="hidden" name="page" value="" />
				<input type="hidden" name="compId" value="" />
			
			<div class="ui-widget categorylist">
				
				<h1>
					 <%=resource.getString("FS_T_TOTALCOUNT")%> :  <%=counts %> 
				</h1>
				<table class="ui-widget ui-widget-content">
					<thead>
						<tr class="ui-widget-header ">
							<th>
								<%=resource.getString("FS_T_LINKORDER")%>
							</th>
							<th>
								<%=resource.getString("FS_T_LINKTITLE")%>
							</th>
							<th>
								<%=resource.getString("FS_T_LINKURL")%>
							</th>
									
							<th>
								<%=resource.getString("FS_T_OPERATION_COL")%>
							</th>							
						</tr>
					</thead>
					<tbody>
									<% if(linklist.size()>0) { 
							Link link = null;
							for(int i=0;i<linklist.size();i++){
								link = (Link)linklist.get(i);
					%>
					
						<tr class="operTR<%=i%2 %>" >
							<td>
								<%=i %>
							</td>
							<td>
								<%=link.getLinkTitle() %>
							</td>
							<td>
								<%=link.getLinkUrl() %>
							</td>
						
							<td class="operation">
								<div><a href="javascript:modify(<%=link.getLinkId() %>,'<%=link.getLinkTitle() %>','<%=link.getLinkUrl() %>');" ><%=resource.getString("FS_T_MODIFY")%></a></div>
							</td>
						</tr>
					<%	}
					}else{ %>

						<tr>
							<td colspan="4">
								<%=resource.getString("FS_M_NORESULT")%>
							</td>
						</tr>
					<%} %>
					</tbody>
				</table>
				<div class="bottom">
					<div id="pager"></div>
				</div>
				<div class="buttonGroupRight">
			   		<div id="btnAdd" ><%=resource.getString("FS_T_ADD")%></div>
					
				</div>	
			</div>
			</form>
		</div>
		
		
		<script type="text/javascript"	>	
		//import scripts below to pages which display in right frame, for ajust the scroll height
		parent.scroll(0,0);
		parent.setFrameHeight(document.body.scrollHeight+200);
		</script>
	</body>
</html>